//package com.eatme.web.sys.workflow.camunda;
//
//import com.eatme.web.app.coupon.common.exception.AppException;
//import com.eatme.web.common.vo.AppResponse;
//import org.apache.commons.io.FilenameUtils;
//import org.camunda.bpm.engine.*;
//import org.camunda.bpm.engine.repository.Deployment;
//import org.camunda.bpm.engine.runtime.ProcessInstance;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.zip.ZipInputStream;
//
//// @Service("camundaServiceImpl")
//public class CamundaServiceImpl {
//
//    private static final Logger LOG = LoggerFactory.getLogger(CamundaServiceImpl.class);
//
//
//    final
//    RuntimeService runtimeService;
//
//    final
//    TaskService taskService;
//
//    final
//    HistoryService historyService;
//
//    final
//    IdentityService identityService;
//
//    final
//    RepositoryService repositoryService;
//
//    public CamundaServiceImpl(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, IdentityService identityService, RepositoryService repositoryService) {
//        this.runtimeService = runtimeService;
//        this.taskService = taskService;
//        this.historyService = historyService;
//        this.identityService = identityService;
//        this.repositoryService = repositoryService;
//    }
//
////    @Autowired
////    ProcessEngine processEngine;
//
//
//    // 驳回任务返回到起点
//
//
//    // 部署流程
//    public AppResponse<Deployment> deploy(MultipartFile file,String name){
//        try {
//            // 获取上传文件名
//            String resourceName = file.getOriginalFilename();
//            //
//            String extension = FilenameUtils.getExtension(resourceName);
//            Deployment deployment;
//            // 获取文件字节流对象
//            InputStream fileInputStream = file.getInputStream();
//            if (extension.equals("zip")) {
//                ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
//                deployment = repositoryService.createDeployment()// 初始化部署
//                        .name(name)
//                        .source("test") // 来源
//                        .addZipInputStream(zipInputStream)
//                        .addInputStream(file.getOriginalFilename(),file.getInputStream())
//                        .deploy();
//
//            } else {
//                deployment = repositoryService.createDeployment()
//                        .name(name)
//                        .source("test") // 来源
//                        .addInputStream(resourceName,fileInputStream)
//                        .deploy();
//            }
//            return AppResponse.ok().data(deployment);
//        } catch (IOException e) {
//            LOG.info("流程部署失败 {}",e);
//            throw new AppException(e);
//        }
//    }
//
//
//    // 启动流程
//    public String startProcess(String key) {
//        // 启动流程实例
//        ProcessInstance instance = runtimeService.startProcessInstanceById(key);
//
//        return instance.getProcessInstanceId();
//    }
//
//    // 完成任务
//    public void completeTask(String taskId) {
//        var task = taskService.createTaskQuery().taskId(taskId).singleResult();
//        Map<String,Object> map = new HashMap<>();
//        taskService.complete(taskId,map);
//    }
//}
